package cn.boge.hrm.controller;

import cn.boge.hrm.doc.CourseDoc;
import cn.boge.hrm.dto.CourseSearchParamDTO;
import cn.boge.hrm.service.ICourseES;
import cn.boge.hrm.util.AjaxResult;
import cn.boge.hrm.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


//ES接口
@RestController
@RequestMapping("/es")
public class ESController {

    @Autowired
    private ICourseES iCourseES;
    //添加
    @RequestMapping(value = "/save")
    @PreAuthorize("hasAuthority('es:saveCourse')")
    public AjaxResult save(@RequestBody  CourseDoc couresDoc){
        iCourseES.save(couresDoc);
        return AjaxResult.me();
    }
    //课程查询
    @RequestMapping(value = "/searchCourse")
    public AjaxResult searchCourse(@RequestBody CourseSearchParamDTO dto){
        try {
            PageList<CourseDoc> pageList = iCourseES.searchCourse(dto);
            return AjaxResult.me().setResultObj(pageList);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}